package cn.csc.module.distribute.dal.mysql.withdraw;

import cn.csc.framework.common.pojo.PageResult;
import cn.csc.framework.mybatis.core.mapper.BaseMapperX;
import cn.csc.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.csc.framework.mybatis.core.query.LambdaUpdateWrapperX;
import cn.csc.module.distribute.controller.admin.withdraw.vo.DistributeWithdrawExportReqVO;
import cn.csc.module.distribute.controller.admin.withdraw.vo.DistributeWithdrawPageReqVO;
import cn.csc.module.distribute.controller.app.withdraw.vo.AppDistributeWithdrawPageReqVO;
import cn.csc.module.distribute.dal.dataobject.withdraw.DistributeWithdrawDO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 提现记录 Mapper
 *
 * @author liuchuang
 */
@Mapper
public interface DistributeWithdrawMapper extends BaseMapperX<DistributeWithdrawDO> {

    default PageResult<DistributeWithdrawDO> selectPage(DistributeWithdrawPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<DistributeWithdrawDO>()
                .eqIfPresent(DistributeWithdrawDO::getUserId, reqVO.getUserId())
                .eqIfPresent(DistributeWithdrawDO::getAuditStatus, reqVO.getAuditStatus())
                .betweenIfPresent(DistributeWithdrawDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(DistributeWithdrawDO::getId));
    }

    default PageResult<DistributeWithdrawDO> selectAppPage(AppDistributeWithdrawPageReqVO reqVO) {
        return  selectPage(reqVO,new LambdaQueryWrapperX<DistributeWithdrawDO>()
                .eq(DistributeWithdrawDO::getUserId,reqVO.getUserId())
                .orderByDesc(DistributeWithdrawDO::getId));
    }

    default List<DistributeWithdrawDO> selectList(DistributeWithdrawExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<DistributeWithdrawDO>()
                .eqIfPresent(DistributeWithdrawDO::getUserId, reqVO.getUserId())
                .eqIfPresent(DistributeWithdrawDO::getAuditStatus, reqVO.getAuditStatus())
                .eqIfPresent(DistributeWithdrawDO::getApplyAmount, reqVO.getApplyAmount())
                .eqIfPresent(DistributeWithdrawDO::getActualAmount, reqVO.getActualAmount())
                .betweenIfPresent(DistributeWithdrawDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(DistributeWithdrawDO::getId));
    }

    default int applyUpdate(DistributeWithdrawDO reqVO) {
        LambdaUpdateWrapperX<DistributeWithdrawDO> updateWrapperX=new LambdaUpdateWrapperX();
        updateWrapperX.set(DistributeWithdrawDO::getAuditStatus,reqVO.getAuditStatus());
        updateWrapperX.set(DistributeWithdrawDO::getActualAmount,reqVO.getActualAmount());
        updateWrapperX.set(DistributeWithdrawDO::getPayVoucher,reqVO.getPayVoucher());
        updateWrapperX.set(DistributeWithdrawDO::getComment,reqVO.getComment());
        updateWrapperX.eq(DistributeWithdrawDO::getId,reqVO.getId());
        return  update(null,updateWrapperX);
    }

    default int auditUpdate(DistributeWithdrawDO reqVO) {
        LambdaUpdateWrapperX<DistributeWithdrawDO> updateWrapperX=new LambdaUpdateWrapperX();
        updateWrapperX.set(DistributeWithdrawDO::getAuditStatus,reqVO.getAuditStatus());
        updateWrapperX.set(DistributeWithdrawDO::getAuditReason,reqVO.getAuditReason());
        updateWrapperX.eq(DistributeWithdrawDO::getId,reqVO.getId());
        return  update(null,updateWrapperX);
    }

    Page<DistributeWithdrawDO> selectWithdrawPage(@Param("req") DistributeWithdrawPageReqVO reqVO, IPage<DistributeWithdrawDO> page);

}
